/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "kh_sle_ssap_server.h"
#include "kh_sle_c_interface_test_entry.h"
#include "kh_sle_host.h"
#include "kh_sle_connect.h"
#include "sle_error_code.h"
#include "sle_unit_test_log.h"
#include "stdlib.h"
static SleSsapsCallbacks *g_sleSsapsUtCbs = NULL;
static SleUuid g_appUuid = {
    .len = 16,
};
static uint8_t g_serverId;
static uint16_t g_connectId;
static uint16_t g_requestId;

void OnSleUtReadRequestCallback(SleErrorCode errCode, uint8_t serverId,
         uint16_t connectId, const SsapsReqReadCbParam *readCbPara)
{
    g_requestId = readCbPara->requestId;
    return;
}

void OnSleUtWriteRequestCallback(SleErrorCode errCode, uint8_t serverId,
         uint16_t connectId, const SsapsReqWriteCbPara *writeCbPara)
{
    return;
}

void OnSleUtExchangeMtuInfo(SleErrorCode errCode, uint8_t serverId, uint16_t connectId, const SsapMtuInfo *mtuInfo)
{
    return;
}

void InitSleSsapsServiceTestLevel0(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    ret = InitSleSsapsService();
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]InitSleSsapsServiceTestLevel0 failed(%d)", ret);
}

void RegisterSsapServerCallbacksTestLevel0(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    ret = RegisterSsapServerCallbacks(g_sleSsapsUtCbs);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]RegisterSsapServerCallbacksTestLevel0 failed(%d)", ret);
}

void AddSsapServerTestLevel0(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    ret = AddSsapServer(&g_appUuid, &g_serverId);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]AddSsapServerTestLevel0 failed(%d)", ret);
}

static uint16_t g_srviceHandle;
void AddServiceTestLevel0(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    ret = AddService(g_serverId, &g_appUuid, true, &g_srviceHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]AddServiceTestLevel0 failed(%d)", ret);
}

static uint16_t g_propertyHandle;
void AddPropertyTestLevel0(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    uint8_t value[10] = {1};
    SsapsPropertyParam propertyParam = {
        .uuid = g_appUuid,
        .permissions = SSAP_PERMISSION_CAN_WRITE,
        .valueLen = 10,
        .value = value,
    };
    ret = AddProperty(g_serverId, g_srviceHandle, &propertyParam, &g_propertyHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]AddPropertyTestLevel0 failed(%d)", ret);
}

static uint16_t g_descriptorHandle;
void AddDescriptorTestLevel0(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    uint8_t value[10] = {1};
    SsapsDescriptorParam descriptorParam = {
        .uuid = g_appUuid,
        .permissions = SSAP_PERMISSION_CAN_READ,
        .operateInd = SSAP_OPERATEIND_BIT_READ,
        .type = SLE_SSAP_DESCRIPTOR_TYPE_CUSTOM,
        .valueLen = 10,
        .value = value,
    };
    ret = AddDescriptor(g_serverId, g_srviceHandle, g_propertyHandle, &descriptorParam, &g_descriptorHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]AddDescriptorTestLevel0 failed(%d)", ret);
}

void StartServiceTestLevel0(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    ret = StartService(g_serverId, g_srviceHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]StartServiceTestLevel0 failed(%d)", ret);
}

void SendResponseTestLevel0(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    uint8_t value[10] = {1};
    SsapsSendRspParam sendRspParam = {
        .requestId = g_requestId,
        .valueLen = 10,
        .value = value,
    };
    ret = SendResponse(g_serverId, g_connectId, &sendRspParam);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]SendResponseTestLevel0 failed(%d)", ret);
}

void NotifyIndicateTestLevel0(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    uint8_t value[10] = {2};
    SsapsNotifyParam notifyParam = {
        .handle = g_propertyHandle,
        .type = SSAP_PROPERTY_TYPE_VALUE_TYPE,
        .valueLen = 10,
        .value = value,
    };
    ret = NotifyIndicate(g_serverId, g_connectId, &notifyParam);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]NotifyIndicateTestLevel0 failed(%d)", ret);
}

void NotifyIndicateByUuidTestLevel0(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    uint8_t value[10] = {3};
    SsapsNotyfyByUuidParam notifyParam = {
        .uuid = g_appUuid,
        .startHandle = 0,
        .endHandle = 100,
        .type = SSAP_PROPERTY_TYPE_VALUE_TYPE,
        .valueLen = 10,
        .value = value,
    };
    ret = NotifyIndicateByUuid(g_serverId, g_connectId, &notifyParam);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]NotifyIndicateByUuidTestLevel0 failed(%d)", ret);
}

void SetServerMtuInfoLevel0(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    SsapMtuInfo mtuInfo = {
        .mtuSize = 300,
        .version = 1,
    };
    ret = SetServerMtuInfo(g_serverId, &mtuInfo);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]SetMtuInfoTestLevel0 failed(%d)", ret);
}

void RemoveAllServicesTestLevel0(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    ret = RemoveAllServices(g_serverId);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]RemoveAllServicesTestLevel0 failed(%d)", ret);
}

void RemoveSsapServerTestLevel0(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    ret = RemoveSsapServer(g_serverId);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]RemoveSsapServerTestLevel0 failed(%d)", ret);
}

void UnregisterSsapServerCallbacksTestLevel0(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    ret = UnregisterSsapServerCallbacks(g_sleSsapsUtCbs);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]UnregisterSsapServerCallbacksTestLevel0 failed(%d)", ret);
}

void DeinitSleSsapsServiceTestLevel0(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    ret = DeinitSleSsapsService();
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]DeinitSleSsapsServiceTestLevel0 failed(%d)", ret);
}

void KhSleSsapsTestLevel0(void)
{
    SLE_UT_LOG("___KhSleSsapsTestLevel0 start");
    InitSleSsapsServiceTestLevel0();
    RegisterSsapServerCallbacksTestLevel0();
    AddSsapServerTestLevel0();
    AddServiceTestLevel0();
    AddPropertyTestLevel0();
    AddDescriptorTestLevel0();
    StartServiceTestLevel0();
    SendResponseTestLevel0();
    NotifyIndicateTestLevel0();
    NotifyIndicateByUuidTestLevel0();
    SetServerMtuInfoLevel0();
    RemoveAllServicesTestLevel0();
    RemoveSsapServerTestLevel0();
    UnregisterSsapServerCallbacksTestLevel0();
    DeinitSleSsapsServiceTestLevel0();
    SLE_UT_LOG("___KhSleSsapsTestLevel0 end");
}

void InitSleSsapsServiceTestLevel1(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    ret = InitSleSsapsService();
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]InitSleSsapsServiceTestLevel1 failed1(%d)", ret);
    //测试重复调用
    ret = InitSleSsapsService();
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]InitSleSsapsServiceTestLevel1 failed2(%d)", ret);
}

void RegisterSsapServerCallbacksTestLevel1(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    //测试入参为NULL
    ret = RegisterSsapServerCallbacks(NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_ERR_INVALID_PARAM, "[KhSleSsapcTest][FAILED]RegisterSsapServerCallbacksTestLevel1 failed1(%d)", ret);
    //测试重复调用
    ret = RegisterSsapServerCallbacks(g_sleSsapsUtCbs);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]RegisterSsapServerCallbacksTestLevel1 failed2(%d)", ret);
    ret = RegisterSsapServerCallbacks(g_sleSsapsUtCbs);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]RegisterSsapServerCallbacksTestLevel1 failed3(%d)", ret);
}

void AddSsapServerTestLevel1(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    //测试入参为NULL
    ret = AddSsapServer(&g_appUuid, NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_ERR_INVALID_PARAM, "[KhSleSsapcTest][FAILED]AddSsapServerTestLevel1 failed1(%d)", ret);
    ret = AddSsapServer(NULL, &g_serverId);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_ERR_INVALID_PARAM, "[KhSleSsapcTest][FAILED]AddSsapServerTestLevel1 failed2(%d)", ret);

    ret = AddSsapServer(&g_appUuid, &g_serverId);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]AddSsapServerTestLevel1 failed3(%d)", ret);
}

void AddServiceTestLevel1(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    //测试入参为NULL
    ret = AddService(g_serverId, &g_appUuid, true, NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_ERR_INVALID_PARAM, "[KhSleSsapcTest][FAILED]AddServiceTestLevel1 failed1(%d)", ret);
    ret = AddService(g_serverId, NULL, true, &g_srviceHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_ERR_INVALID_PARAM, "[KhSleSsapcTest][FAILED]AddServiceTestLevel1 failed2(%d)", ret);

    ret = AddService(g_serverId, &g_appUuid, true, &g_srviceHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]AddServiceTestLevel1 failed3(%d)", ret);
}

void AddPropertyTestLevel1(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    uint8_t value[10] = {1};
    SsapsPropertyParam propertyParam = {
        .uuid = g_appUuid,
        .permissions = SSAP_PERMISSION_CAN_WRITE,
        .valueLen = 10,
        .value = value,
    };
    //测试入参为NULL
    ret = AddProperty(g_serverId, g_srviceHandle, NULL, &g_propertyHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_ERR_INVALID_PARAM, "[KhSleSsapcTest][FAILED]AddPropertyTestLevel1 failed1(%d)", ret);
    ret = AddProperty(g_serverId, g_srviceHandle, &propertyParam, NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_ERR_INVALID_PARAM, "[KhSleSsapcTest][FAILED]AddPropertyTestLevel1 failed2(%d)", ret);

    ret = AddProperty(g_serverId, g_srviceHandle, &propertyParam, &g_propertyHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]AddPropertyTestLevel1 failed3(%d)", ret);
}

void AddDescriptorTestLevel1(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    uint8_t value[10] = {1};
    SsapsDescriptorParam descriptorParam = {
        .uuid = g_appUuid,
        .permissions = SSAP_PERMISSION_CAN_READ,
        .operateInd = SSAP_OPERATEIND_BIT_READ,
        .type = SLE_SSAP_DESCRIPTOR_TYPE_CUSTOM,
        .valueLen = 10,
        .value = value,
    };
    //测试入参为NULL
    ret = AddDescriptor(g_serverId, g_srviceHandle, g_propertyHandle, NULL, &g_descriptorHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_ERR_INVALID_PARAM, "[KhSleSsapcTest][FAILED]AddDescriptorTestLevel1 failed1(%d)", ret);
    ret = AddDescriptor(g_serverId, g_srviceHandle, g_propertyHandle, &descriptorParam, NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_ERR_INVALID_PARAM, "[KhSleSsapcTest][FAILED]AddDescriptorTestLevel1 failed2(%d)", ret);

    ret = AddDescriptor(g_serverId, g_srviceHandle, g_propertyHandle, &descriptorParam, &g_descriptorHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]AddDescriptorTestLevel1 failed3(%d)", ret);
}

void StartServiceTestLevel1(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    ret = StartService(g_serverId, g_srviceHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]StartServiceTestLevel1 failed1(%d)", ret);
    //测试重复调用
    ret = StartService(g_serverId, g_srviceHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]StartServiceTestLevel1 failed2(%d)", ret);
}

void SendResponseTestLevel1(void)
{
    uint8_t value[10] = {5};
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    SsapsSendRspParam sendRspParam = {
        .requestId = g_requestId,
        .valueLen = 10,
        .value = value,
    };
    //测试入参为NULL
    ret = SendResponse(g_serverId, g_connectId, NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_ERR_INVALID_PARAM, "[KhSleSsapcTest][FAILED]SendResponseTestLevel1 failed1(%d)", ret);

    ret = SendResponse(g_serverId, g_connectId, &sendRspParam);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]SendResponseTestLevel1 failed2(%d)", ret);
}

void NotifyIndicateTestLevel1(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    uint8_t value[10] = {2};
    SsapsNotifyParam notifyParam = {
        .handle = g_propertyHandle,
        .type = SSAP_PROPERTY_TYPE_VALUE_TYPE,
        .valueLen = 10,
        .value = value,
    };
    //测试入参为NULL
    ret = NotifyIndicate(g_serverId, g_connectId, NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_ERR_INVALID_PARAM, "[KhSleSsapcTest][FAILED]NotifyIndicateTestLevel1 failed1(%d)", ret);

    ret = NotifyIndicate(g_serverId, g_connectId, &notifyParam);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]NotifyIndicateTestLevel1 failed2(%d)", ret);
}

void NotifyIndicateByUuidTestLevel1(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    uint8_t value[10] = {3};
    SsapsNotyfyByUuidParam notifyParam = {
        .uuid = g_appUuid,
        .startHandle = 0,
        .endHandle = 100,
        .type = SSAP_PROPERTY_TYPE_VALUE_TYPE,
        .valueLen = 10,
        .value = value,
    };
    //测试入参为NULL
    ret = NotifyIndicateByUuid(g_serverId, g_connectId, NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_ERR_INVALID_PARAM, "[KhSleSsapcTest][FAILED]NotifyIndicateByUuidTestLevel1 failed1(%d)", ret);

    ret = NotifyIndicateByUuid(g_serverId, g_connectId, &notifyParam);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]NotifyIndicateByUuidTestLevel1 failed2(%d)", ret);
}

void SetServerMtuInfoLevel1(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    SsapMtuInfo mtuInfo = {
        .mtuSize = 300,
        .version = 1,
    };
    //测试入参为NULL
    ret = SetServerMtuInfo(g_serverId, NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_ERR_INVALID_PARAM, "[KhSleSsapcTest][FAILED]SetMtuInfoTestLevel1 failed1(%d)", ret);

    ret = SetServerMtuInfo(g_serverId, &mtuInfo);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]SetMtuInfoTestLevel1 failed2(%d)", ret);
}

void RemoveAllServicesTestLevel1(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    ret = RemoveAllServices(g_serverId);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]RemoveAllServicesTestLevel1 failed1(%d)", ret);
    //测试重复调用
    ret = RemoveAllServices(g_serverId);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]RemoveAllServicesTestLevel1 failed2(%d)", ret);
}

void RemoveSsapServerTestLevel1(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    ret = RemoveSsapServer(g_serverId);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]RemoveSsapServerTestLevel1 failed1(%d)", ret);
    //测试重复调用
    ret = RemoveSsapServer(g_serverId);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]RemoveSsapServerTestLevel1 failed2(%d)", ret);
}

void UnregisterSsapServerCallbacksTestLevel1(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    //测试入参为NULL
    ret = UnregisterSsapServerCallbacks(NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_ERR_INVALID_PARAM, "[KhSleSsapcTest][FAILED]UnregisterSsapServerCallbacksTestLevel1 failed1(%d)", ret);

    ret = UnregisterSsapServerCallbacks(g_sleSsapsUtCbs);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]UnregisterSsapServerCallbacksTestLevel1 failed2(%d)", ret);
    //测试重复调用
    ret = UnregisterSsapServerCallbacks(g_sleSsapsUtCbs);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]UnregisterSsapServerCallbacksTestLevel1 failed3(%d)", ret);
}

void DeinitSleSsapsServiceTestLevel1(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    ret = DeinitSleSsapsService();
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[KhSleSsapcTest][FAILED]DeinitSleSsapsServiceTestLevel1 failed1(%d)", ret);
    //测试重复调用
    ret = DeinitSleSsapsService();
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_ERR_NOT_READY, "[KhSleSsapcTest][FAILED]DeinitSleSsapsServiceTestLevel1 failed2(%d)", ret);
}

void KhSleSsapsTestLevel1(void)
{
    SLE_UT_LOG("___KhSleSsapsTestLevel1 start");
    InitSleSsapsServiceTestLevel1();
    RegisterSsapServerCallbacksTestLevel1();
    AddSsapServerTestLevel1();
    AddServiceTestLevel1();
    AddPropertyTestLevel1();
    AddDescriptorTestLevel1();
    StartServiceTestLevel1();
    SendResponseTestLevel1();
    NotifyIndicateTestLevel1();
    NotifyIndicateByUuidTestLevel1();
    SetServerMtuInfoLevel1();
    RemoveAllServicesTestLevel1();
    RemoveSsapServerTestLevel1();
    UnregisterSsapServerCallbacksTestLevel1();
    DeinitSleSsapsServiceTestLevel1();
    SLE_UT_LOG("___KhSleSsapsTestLevel1 end");
}

SleErrorCode InitKhSleSsapsTestEntry(void)
{
    SleErrorCode ret = SLE_ERR_UNKNOWN;
    g_sleSsapsUtCbs = (SleSsapsCallbacks *)malloc(sizeof(SleSsapsCallbacks));
    SLE_UT_CHECK_AND_RETURN_RET(g_sleSsapsUtCbs != NULL, SLE_ERR_SYSTEM_WRONG);
    g_sleSsapsUtCbs->OnRequestReadCb = OnSleUtReadRequestCallback;
    g_sleSsapsUtCbs->OnRequestWriteCb = OnSleUtWriteRequestCallback;
    g_sleSsapsUtCbs->OnChangeMtuCb = OnSleUtExchangeMtuInfo;
    SleConnectDev  connectDevList[SLE_MAX_CONNECT_ID_NUM];
    uint16_t connectListLen = SLE_MAX_CONNECT_ID_NUM;
    ret = GetConnectDevList(connectDevList, &connectListLen);
    SLE_UT_CHECK_AND_RETURN_RET(ret == SLE_NO_ERROR, ret);
    g_connectId = connectDevList[0].connId;
    uint8_t uuid[UUID_LEN] = {2};
    memcpy(g_appUuid.uuid, uuid, UUID_LEN);
    ret = SLE_NO_ERROR;
    return ret;
}

SleErrorCode DeinitKhSleSsapsTestEntry(void)
{
    if (g_sleSsapsUtCbs != NULL) {
        free(g_sleSsapsUtCbs);
    }
    g_sleSsapsUtCbs = NULL;
    return SLE_NO_ERROR;
}

void KhSleSsapsTestEntry(void)
{
    SLE_UT_LOG("__KhSleSsapsTestEntry start");
    SleErrorCode ret = InitKhSleSsapsTestEntry();
    SLE_UT_CHECK_AND_RETURN_LOG(ret == SLE_NO_ERROR, "[KhSleSsapsTest][FAILED]InitKhSleSsapsTestEntry failed(%d)", ret);
    KhSleSsapsTestLevel0();
    KhSleSsapsTestLevel1();
    ret = DeinitKhSleSsapsTestEntry();
    SLE_UT_CHECK_AND_RETURN_LOG(ret == SLE_NO_ERROR, "[KhSleSsapsTest][FAILED]DeinitKhSleSsapsTestEntry failed(%d)", ret);
    SLE_UT_LOG("__KhSleSsapsTestEntry end");
}
